package com.sanpu.kxe.business.main.view;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.sanpu.kxe.BuildConfig;
import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.module.widget.EditTextWithDel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;

/**
 * Description：测试专用
 * Created by 薛勇军 on 2018/7/12.
 */

public class SettingHostActivity extends BaseTitleActivity {

    /**
     * 生产环境
     */
    private final String BASE_URL = "http://app.sanpupay.com:8581/kingpay_web/";

    /**
     * 开发环境
     */
    private final String BASE_DEV_URL = "http://kql.ngrok.alifepay.com:8380/";
    /**
     * 测试环境
     */
    private final String BASE_TEST_URL = "http://192.168.3.225:8080/";
    /**
     * 准生产环境
     */
    private final String BASE_SETUP_URL = "http://124.232.152.234:8201/kingpay_web/";

    @Bind(R.id.edit)
    EditTextWithDel vEdit;
    @Bind(R.id.list_view)
    ListView vListView;

    private SimpleAdapter mSimpleAdapter;

    private String[] names = new String[]{"生产", "开发", "测试", "准生产"};
    private String[] descs = new String[]
            {BASE_URL, BASE_DEV_URL, BASE_TEST_URL, BASE_SETUP_URL};
    private List<Map<String, String>> listItems;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_setting_host;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("设置服务器地址");
        commonTitle.showRightTextView("保存");
    }

    @Override
    protected void setListener() {
        super.setListener();
        commonTitle.setRightOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (BuildConfig.DEBUG) {
                    UrlConstants.setBaseUrl(vEdit.getText().toString());
                    onBackPressed();
                }
            }
        });
        vListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                vEdit.setText(listItems.get(position).get("des"));
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        listItems = new ArrayList<>();
        vEdit.setText(UrlConstants.getBaseUrl());

        for (int i = 0; i < names.length; i++) {
            Map<String, String> listItem = new HashMap<>();
            listItem.put("title", names[i]);
            listItem.put("des", descs[i]);
            listItems.add(listItem);
        }
        mSimpleAdapter = new SimpleAdapter(this, listItems, R.layout.item_setting_host,
                new String[]{"title", "des"},
                new int[]{R.id.title, R.id.des});
        vListView.setAdapter(mSimpleAdapter);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }
}
